﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestGit4_数组排序
{
    class Program
    {
        /// <summary>
        /// 数组排序
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //求出最大最小
            int[] numbers = { 97, 65, 32, 17, 58, 43, 79, 81, 23, 10 };
            int nummax = numbers[0];
            int nummin = numbers[0];
            for (int i = 0; i < numbers.Length; i++)
            {
                if (nummax < numbers[i])
                {
                    nummax = numbers[i];
                }
                if (nummin > numbers[i])
                {
                    nummin = numbers[i];
                }
            }
            Console.WriteLine($"最大值：{nummax},最小值：{nummin}");
            //排顺序
            int[] array = { 97, 65, 32, 17, 58, 43, 79, 81, 23, 10 };
            Console.Write("数组排序前的结果为：");
            foreach (int n in array)
            {
                Console.Write("{0}", n + " ");
            }
            Console.WriteLine();
            for (int i = 0; i < array.Length; i++)
            {
                for (int j = i; j < array.Length; j++)
                {
                    if (array[i] < array[j])
                    {
                        int temp = array[i];
                        array[i] = array[j];
                        array[j] = temp;
                    }
                }
            }
            Console.Write("数组排序后的结果为：");
            foreach (int n in array)
            {
                Console.Write("{0}", n + " ");
            }
            Console.ReadKey();
        }
    }
}
